package com.zs.controller;

import com.zs.entity.Cp;
import com.zs.entity.Cplb;
import com.zs.service.CpService;
import com.zs.service.CplbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/cp")
@Controller
public class CpController {

    @Autowired
    private CpService cpService;

    @Autowired
    private CplbService cplbService;

    @RequestMapping("/getAllCp")
    public String getAllCp(Model model) {
        List<Cp> list = cpService.getAllCp();
        model.addAttribute("list", list);
        return "cpgl";
    }

    @RequestMapping("/toTj")
    public String toTj(Model model) {
        List<Cplb> lbList = cplbService.getAll();
        model.addAttribute("lbList", lbList);
        return "cptj";
    }

    @RequestMapping("/cpAdd")
    public String cpAdd(Cp cp) {
        cpService.cpAdd(cp);
        return "redirect:/cp/getAllCp.do";
    }
}
